#include "lwip/udp.h"
#include "lwip/apps/tftp_server.h"
#include "lwip/apps/tftp_opts.h"
#ifdef LFS
#include "flashFs.h"
void *tftp_open(const char *fname, const char *mode, u8_t write)
{
    FlashFile *flag = new FlashFile();
    if (write)
    {
        flag->open_write(fname);
        return flag;
    }
    else
    {
        flag->open_rdonly(fname);
        return flag;
    }
    flag->close();
    return 0;
}
void tftp_close(void *handle)
{
    FlashFile *flag = (FlashFile *)handle;
    flag->close();
}
int tftp_read(void *handle, void *buf, int bytes)
{
    FlashFile *flag = (FlashFile *)handle;
    flag->read((char *)buf, bytes);
}
int tftp_write(void *handle, struct pbuf *p)
{
    FlashFile *flag = (FlashFile *)handle;
    flag->write((const char *)p->payload, p->len);
}
struct tftp_context tftp_ctx
{
    tftp_open, tftp_close, tftp_read, tftp_write
};
#endif